<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增人员信息')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-wzxUser-add">
            <input name="deptId" type="hidden" id="treeId"/>
            <div class="form-group">    
                <label class="col-sm-3 control-label">部门：</label>
                <div class="col-sm-8">
                    <input name="deptName" onclick="selectDeptTree()" id="treeName" type="text" placeholder="请选择归属部门" class="form-control">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">人员姓名：</label>
                <div class="col-sm-8">
                    <input name="userName" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label " >开始时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="createTime" class="form-control createTime" placeholder="无假期不需时间" type="text">
                        <span class="input-group-addon hiddenSome"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">结束时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="endTime" class="form-control endTime" onblur="checkTime()" placeholder="无假期不需时间" type="text">
                        <span class="input-group-addon hiddenSome" ><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label ">协同人：</label>
                <div class="col-sm-8">
                    <input name="withWork" class="form-control hiddenSome" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label ">目的地：</label>
                <div class="col-sm-8">
                    <input name="dest" class="form-control hiddenSome" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label ">原因：</label>
                <div class="col-sm-8">
                    <input name="reason" class="form-control hiddenSome" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
<!--                    <input name="state" class="form-control" type="text">-->
                    <select name="state" id="state" class="form-control">
                        <option value="事假">事假</option>
                        <option value="正常">正常</option>
                        <option value="病假">病假</option>
                    </select>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/wzxUser"
        $("#form-wzxUser-add").validate({
            focusCleanup: true
        });


            $("#state").bind("input propertychange",function(event){
                // console.log($('#state').val() == "正常")
                if($('#state').val() == "正常"){
                    $('.hiddenSome').attr("disabled", "disabled");
                }else{
                    $('.hiddenSome').removeAttr("disabled");
                }
            });


        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-wzxUser-add').serialize());
            }
        }

        $("input[name='endTime'],input[name='createTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        function checkTime() {
            console.log($('.createTime').val())
            console.log($('.endTime').val())
            if ($('.createTime').val() > $('.endTime').val()){
                $.modal.alertWarning("开始时间大于结束时间");
            }
        }


        /* 用户管理-新增-选择部门树 */
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "system/user/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            console.log(deptId)
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            $.modal.close(index);
        }
    </script>
</body>
</html>